package com.example.demo.service;

import com.example.demo.entity.PersonEvent;
import com.example.demo.mapper.PersonEventMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonEventService {

    @Resource
    private PersonEventMapper personEventMapper;

    public void add(PersonEvent event) {
        personEventMapper.insert(event);
    }

    public void update(PersonEvent event) {
        personEventMapper.updateById(event);
    }

    public void deleteById(Long eventId) {
        personEventMapper.deleteById(eventId);
    }

    public PersonEvent selectById(Long eventId) {
        return personEventMapper.selectById(eventId);
    }

    public List<PersonEvent> selectAll() {
        return personEventMapper.selectAll();
    }

    public List<PersonEvent> selectByPersonId(Long personId) {
        return personEventMapper.selectByPersonId(personId);
    }

    public PageInfo<PersonEvent> selectPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PersonEvent> list = personEventMapper.selectAll();
        return PageInfo.of(list);
    }
}